# -*- coding:utf-8 -*-
# @FileName  :dhcc_ent_5_reqresult.py
# @Time      :2020/12/16 10:24
# @Author    :Zhoujirong
# @Desc      : 审批结果
import parameterized
import time
from common.utils import download
from biz.flow.ent_reqresult import EntReqResultRequest
from biz.flow.ent_report import EntReportRequest
from common.log import Log
from biz.cases.base_case import BaseCase
from common.params_operator import Param

class TestEntReqResult(BaseCase):
    data_file_name = 'ent_reqresult.yaml'
    @classmethod
    def setUpClass(cls):
        cls.cookie = BaseCase().get_token()

    @parameterized.parameterized.expand(Param.from_excel('ent_reqresult_getpage.xls'))
    def test_get_page_params(self, curPage,
                             maxSize,
                             search_EQ_enterpriseName,
                             search_EQ_signCode,
                             search_EQ_uniformSocialCredCode,
                             search_EQ_orgInstCode,
                             search_EQ_qryReason,
                             search_EQ_queryFormat,
                             search_EQ_queryType,
                             search_EQ_status,
                             search_EQ_resultStatus,
                             check, desc):
        self._testMethodDoc = desc
        temp = '%s - %s' % (time.strftime('%Y-%m-%d', time.localtime()), time.strftime('%Y-%m-%d', time.localtime()))
        search_GTE_LTE_operTime_DATE_RANGE = temp
        Log.info(search_GTE_LTE_operTime_DATE_RANGE)
        ret = EntReqResultRequest.get_page(curPage,
                    maxSize,
                    search_EQ_enterpriseName,
                    search_EQ_signCode,
                    search_EQ_uniformSocialCredCode,
                    search_EQ_orgInstCode,
                    search_EQ_qryReason,
                    search_EQ_queryFormat,
                    search_EQ_queryType,
                    search_EQ_status,
                    search_EQ_resultStatus,
                    search_GTE_LTE_operTime_DATE_RANGE, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)

    def get_page(self):
        '''检索被拒绝的数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_uniformSocialCredCode  = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_orgInstCode  = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_qryReason  = self.file_data.get('search_EQ_qryReason')
        search_EQ_queryFormat  = self.file_data.get('search_EQ_queryFormat')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_status  = self.file_data.get('search_EQ_status')
        search_EQ_resultStatus = self.file_data.get('search_EQ_resultStatus')
        search_GTE_LTE_operTime_DATE_RANGE = self.file_data.get('search_GTE_LTE_operTime_DATE_RANGE')
        ret = EntReqResultRequest.get_page(curPage,
                    maxSize,
                    search_EQ_enterpriseName,
                    search_EQ_signCode,
                    search_EQ_uniformSocialCredCode,
                    search_EQ_orgInstCode,
                    search_EQ_qryReason,
                    search_EQ_queryFormat,
                    search_EQ_queryType,
                    search_EQ_status,
                    search_EQ_resultStatus,
                    search_GTE_LTE_operTime_DATE_RANGE,self.cookie)
        Log.info(ret)
        return ret.list[0].id

    def test_a_detail(self):
        '''详情框架'''
        id = self.get_page()
        ret = EntReqResultRequest.detail(id, self.cookie)
        Log.info(ret)
        self.assertIn('企业审批结果',ret)

    def reqresult_findbyid(self):
        '''查看详情-基本信息'''
        id = self.get_page()
        ret = EntReqResultRequest.reqresult_findbyid(id, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.archiveId)
        Log.info('%s+%s'%(ret.archiveId,ret.id))
        return ret.archiveId,ret.id

    def test_b_archive_findbyid(self):
        '''查看详情-授权信息'''
        archiveId,id = self.reqresult_findbyid()
        ret = EntReqResultRequest.archive_findbyid(archiveId, self.cookie)
        Log.info(ret)
        self.assertEqual(archiveId,ret.id)

    def test_c_findbyarchiveid(self):
        '''查看详情-授权档案信息'''
        archiveId,id = self.reqresult_findbyid()
        ret = EntReqResultRequest.findbyarchiveid(archiveId, self.cookie)
        Log.info(ret)
        self.assertEqual(archiveId, ret[0]['archiveId'])

    def test_d_resubmit(self):
        '''重新提交请求'''
        ids = self.get_page()
        ret = EntReqResultRequest.resubmit_task(ids,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertIn('操作成功',ret.msg)

    def get_page_pass(self):
        '''检索审批通过的数据'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_orgInstCode = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_qryReason = self.file_data.get('search_EQ_qryReason')
        search_EQ_queryFormat = self.file_data.get('search_EQ_queryFormat')
        search_EQ_queryType = self.file_data.get('search_EQ_queryType')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_resultStatus = 2
        search_GTE_LTE_operTime_DATE_RANGE = self.file_data.get('search_GTE_LTE_operTime_DATE_RANGE')
        ret = EntReqResultRequest.get_page(curPage,
                    maxSize,
                    search_EQ_enterpriseName,
                    search_EQ_signCode,
                    search_EQ_uniformSocialCredCode,
                    search_EQ_orgInstCode,
                    search_EQ_qryReason,
                    search_EQ_queryFormat,
                    search_EQ_queryType,
                    search_EQ_status,
                    search_EQ_resultStatus,
                    search_GTE_LTE_operTime_DATE_RANGE, self.cookie)
        Log.info(ret)
        return ret.list[0]

    def test_e_applyreport(self):
        '''异步查询检查本地'''
        data = self.get_page_pass()
        archiveId = data.archiveId
        archiveViewStatus = data.archiveViewStatus
        assocbsnssData = data.assocbsnssData
        dsRegiNo = data.dsRegiNo
        frgCorpNo = data.frgCorpNo
        gsRegiNo = data.gsRegiNo
        orgCreditCode = data.orgCreditCode
        orgInstCode = data.orgInstCode
        regiTypeCode = data.regiTypeCode
        uniformSocialCredCode = data.uniformSocialCredCode
        checkinfoId = data.checkinfoId
        clientIp = data.clientIp
        enterpriseName = data.enterpriseName
        creditUser = data.creditUser
        ext1 = data.ext1
        ext2 = data.ext2
        ext3 = data.ext3
        ext4 = data.ext4
        ext5 = data.ext5
        ext6 = data.ext6
        id = data.id
        note = data.note
        operOrg = data.operOrg
        operTime = data.operTime
        operator = data.operator
        president = data.president
        qryReason = data.qryReason
        queryFormat = data.queryFormat
        queryTime = data.queryTime
        queryType = data.queryType
        reason = data.reason
        refuseReasons = data.refuseReasons
        rekOrg = data.rekOrg
        rekTime = data.rekTime
        rekType = data.rekType
        rekUser = data.rekUser
        remarks = data.remarks
        reqId = data.reqId
        resCode = data.resCode
        resMsg = data.resMsg
        resultStatus = data.resultStatus
        resultType = data.resultType
        serialNumber = data.serialNumber
        source = data.source
        status = data.status
        ret = EntReqResultRequest.applyreport(archiveId,
                        archiveViewStatus,
                        assocbsnssData,
                        checkinfoId,
                        clientIp,
                        enterpriseName,
                        creditUser,
                        ext1,
                        ext2,
                        ext3,
                        ext4,
                        ext5,
                        ext6,
                        id,
                        note,
                        operOrg,
                        operTime,
                        operator,
                        president,
                        qryReason,
                        queryFormat,
                        queryTime,
                        queryType,
                        reason,
                        refuseReasons,
                        rekOrg,
                        rekTime,
                        rekType,
                        rekUser,
                        remarks,
                        reqId,
                        resCode,
                        resMsg,
                        resultStatus,
                        resultType,
                        serialNumber,
                        source,
                        status,dsRegiNo,frgCorpNo,gsRegiNo,
                        orgCreditCode,orgInstCode,regiTypeCode,
                        uniformSocialCredCode,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.resultMsg)

    def showcreditreport(self):
        '''异步查询人行报告'''
        data = self.get_page_pass()
        archiveId = data.archiveId
        archiveViewStatus = data.archiveViewStatus
        assocbsnssData = data.assocbsnssData
        dsRegiNo = data.dsRegiNo
        frgCorpNo = data.frgCorpNo
        gsRegiNo = data.gsRegiNo
        orgCreditCode = data.orgCreditCode
        orgInstCode = data.orgInstCode
        regiTypeCode = data.regiTypeCode
        uniformSocialCredCode = data.uniformSocialCredCode
        checkinfoId = data.checkinfoId
        clientIp = data.clientIp
        enterpriseName = data.enterpriseName
        creditUser = data.creditUser
        ext1 = data.ext1
        ext2 = data.ext2
        ext3 = data.ext3
        ext4 = data.ext4
        ext5 = data.ext5
        ext6 = data.ext6
        id = data.id
        note = data.note
        operOrg = data.operOrg
        operTime = data.operTime
        operator = data.operator
        president = data.president
        qryReason = data.qryReason
        queryFormat = data.queryFormat
        queryTime = data.queryTime
        queryType = data.queryType
        reason = data.reason
        refuseReasons = data.refuseReasons
        rekOrg = data.rekOrg
        rekTime = data.rekTime
        rekType = data.rekType
        rekUser = data.rekUser
        remarks = data.remarks
        reqId = data.reqId
        resCode = data.resCode
        resMsg = data.resMsg
        resultStatus = data.resultStatus
        resultType = data.resultType
        serialNumber = data.serialNumber
        source = data.source
        status = data.status
        ret = EntReqResultRequest.showcreditreport(archiveId,
                        archiveViewStatus,
                        assocbsnssData,
                        checkinfoId,
                        clientIp,
                        enterpriseName,
                        creditUser,
                        ext1,
                        ext2,
                        ext3,
                        ext4,
                        ext5,
                        ext6,
                        id,
                        note,
                        operOrg,
                        operTime,
                        operator,
                        president,
                        qryReason,
                        queryFormat,
                        queryTime,
                        queryType,
                        reason,
                        refuseReasons,
                        rekOrg,
                        rekTime,
                        rekType,
                        rekUser,
                        remarks,
                        reqId,
                        resCode,
                        resMsg,
                        resultStatus,
                        resultType,
                        serialNumber,
                        source,
                        status,dsRegiNo,frgCorpNo,gsRegiNo,
                        orgCreditCode,orgInstCode,regiTypeCode,
                        uniformSocialCredCode, self.cookie)
        Log.info(ret)
        self.assertIn('inquire/revealReport?recordId=', ret.url)
        return ret.url[30:]

    def localcreditreport(self):
        '''异步查询本地报告'''
        data = self.get_page_pass()
        data = self.get_page_pass()
        archiveId = data.archiveId
        archiveViewStatus = data.archiveViewStatus
        assocbsnssData = data.assocbsnssData
        dsRegiNo = data.dsRegiNo
        frgCorpNo = data.frgCorpNo
        gsRegiNo = data.gsRegiNo
        orgCreditCode = data.orgCreditCode
        orgInstCode = data.orgInstCode
        regiTypeCode = data.regiTypeCode
        uniformSocialCredCode = data.uniformSocialCredCode
        checkinfoId = data.checkinfoId
        clientIp = data.clientIp
        enterpriseName = data.enterpriseName
        creditUser = data.creditUser
        ext1 = data.ext1
        ext2 = data.ext2
        ext3 = data.ext3
        ext4 = data.ext4
        ext5 = data.ext5
        ext6 = data.ext6
        id = data.id
        note = data.note
        operOrg = data.operOrg
        operTime = data.operTime
        operator = data.operator
        president = data.president
        qryReason = data.qryReason
        queryFormat = data.queryFormat
        queryTime = data.queryTime
        queryType = data.queryType
        reason = data.reason
        refuseReasons = data.refuseReasons
        rekOrg = data.rekOrg
        rekTime = data.rekTime
        rekType = data.rekType
        rekUser = data.rekUser
        remarks = data.remarks
        reqId = data.reqId
        resCode = data.resCode
        resMsg = data.resMsg
        resultStatus = data.resultStatus
        resultType = data.resultType
        serialNumber = data.serialNumber
        source = data.source
        status = data.status
        ret = EntReqResultRequest.localcreditreport(archiveId,
                        archiveViewStatus,
                        assocbsnssData,
                        checkinfoId,
                        clientIp,
                        enterpriseName,
                        creditUser,
                        ext1,
                        ext2,
                        ext3,
                        ext4,
                        ext5,
                        ext6,
                        id,
                        note,
                        operOrg,
                        operTime,
                        operator,
                        president,
                        qryReason,
                        queryFormat,
                        queryTime,
                        queryType,
                        reason,
                        refuseReasons,
                        rekOrg,
                        rekTime,
                        rekType,
                        rekUser,
                        remarks,
                        reqId,
                        resCode,
                        resMsg,
                        resultStatus,
                        resultType,
                        serialNumber,
                        source,
                        status,dsRegiNo,frgCorpNo,gsRegiNo,
                        orgCreditCode,orgInstCode,regiTypeCode,
                        uniformSocialCredCode, self.cookie)
        Log.info(ret)
        self.assertIn('inquire/revealReport?recordId=', ret.url)
        return ret.url[30:]

    def revealreport1(self):
        '''查人行的报告模板'''
        recordId = self.showcreditreport()
        ret = EntReqResultRequest.revealreport(recordId,self.cookie)
        Log.info(ret)
        self.assertIn('企业信用报告（授信机构版）',ret)
        return recordId

    def revealreport2(self):
        '''查本地的报告模板'''
        recordId = self.localcreditreport()
        ret = EntReqResultRequest.revealreport(recordId,self.cookie)
        Log.info(ret)
        self.assertIn('企业信用报告（授信机构版）',ret)
        return recordId

    def test_g_show_report1(self):
        '''展示人行的报告'''
        recordId = self.revealreport1()
        ret = EntReportRequest.ent_reveal_report(recordId,self.cookie)
        Log.info(ret)
        size = download('企业人行信用报告dhcc_ent_5_reqresultDtest_g_show_report1%s.html'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_p_show_report2(self):
        '''展示本地的报告'''
        recordId = self.revealreport2()
        ret = EntReportRequest.ent_reveal_report(recordId,self.cookie)
        Log.info(ret)
        size = download('企业本地信用报告dhcc_ent_5_reqresultDtest_p_show_report2%s.html' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)




if __name__ == "__main__":
    pass